package Operation;

import Book.BookList;

import java.util.Scanner;

//归还书籍
public class ReturnBook implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书.....");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要归还的图书的名字：");
        String bookName = sc.nextLine();
        int count = bookList.getUsedSize();
        for (int i = 0; i < count; i++) {
            if(bookList.getBooks()[i].getName().equals(bookName)){
                if(bookList.getBooks()[i].getIsBorrow()){
                    bookList.getBooks()[i].setBorrowed(false);
                    System.out.println("还书成功。");
                    return;
                }else {
                    System.out.println("该书已经被归还，无需归还！！！");
                    return;
                }
            }
        }
        System.out.println("未找到"+bookName+"这本书，无法归还！！！");
    }
}
